package com.sf.service.impl;

import com.sf.domain.Employee;
import com.sf.mapper.EmployeeMapper;
import com.sf.service.ILoginService;
import com.sf.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements ILoginService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public Employee login(String username, String password) {
        // 判断账号和密码不能为空
        if(StringUtils.isEmpty(username)|| StringUtils.isEmpty(password)){
            throw new RuntimeException("账号和密码不能为空");
        }

        // 根据账号和密码查询用户信息
        Employee employee = employeeMapper.login(username, password);
        // 判断employee == null
        if(employee == null){
            throw new RuntimeException("账号或者密码错误");
        }
        return employee;
    }
}
